#include "LockedObstacle.h"
#include "Game.h"
#include <vector>
#include "Util.h"

LockedObstacle::LockedObstacle(GenericType type, LockType lockType, bool locked) : Obstacle(type) {
	m_lockType = lockType;
	if(m_lockType == LT_NONE)
		m_locked = false;
	else
		m_locked = locked;
}

LockedObstacle::LockedObstacle(GenericType type, std::ifstream& file) : Obstacle(type, file) {
	int* tokens = Util::intSplit(file);
	m_lockType = LockType(tokens[0]);
	m_locked = tokens[1] == 1;
	delete[] tokens;
}

LockedObstacle::~LockedObstacle() {
}

void LockedObstacle::save(std::ofstream& file) const {
	Obstacle::save(file);
	file << m_lockType << " " << (m_locked ? 1 : 0) << "\n";
}

void LockedObstacle::breakLock(bool destroyed) {
	m_lockType = LT_NONE;
	m_locked = destroyed;
}

bool LockedObstacle::toggleLock() {
	m_locked = !m_locked;
	return true;
}